package com.mall.shopping.services;
import com.mall.shopping.IHomepageService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.PanelListToPanelListConverter;
import com.mall.shopping.dal.entitys.Item;
import com.mall.shopping.dal.entitys.Panel;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.entitys.PanelContentItem;
import com.mall.shopping.dal.persistence.ItemMapper;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dal.persistence.PanelMapper;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.PanelDto;
import com.mall.shopping.utils.ExceptionProcessorUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;



//@Service
//@Slf4j
//@Component
public class IHomepageServiceImpl implements IHomepageService {

//    @Autowired
//    PanelMapper panelMapper;
//
//    @Autowired
//    PanelContentMapper panelContentMapper;
//
//    @Autowired
//    ItemMapper itemMapper;
//
//    @Autowired
//    PanelListToPanelListConverter panelListConverter;
//
//
//    @Override
//    public HomePageResponse homepage() {
//        HomePageResponse response = new HomePageResponse();
//        try {
//            List<Panel> panels = panelMapper.selectAll();
//            for (Panel panel : panels) {
//                List<PanelContentItem> panelContentItems = new ArrayList<>();
//                if (panel.getId() != 8) {
//                    Example example = new Example(PanelContent.class);
//                    example.createCriteria().andEqualTo("panelId", panel.getId());
//                    List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
//                    for (PanelContent panelContent : panelContents) {
//                        Item item = itemMapper.selectByPrimaryKey(panelContent.getProductId());
//                        PanelContentItem panelContentItem =
//                                panelListConverter.panelPanelContentToContentItem(panelContent, item.getTitle(), item.getPrice(), item.getSellPoint());
//                        panelContentItems.add(panelContentItem);
//                    }
//                }else{
//                    Example example = new Example(PanelContent.class);
//                    example.createCriteria().andEqualTo("panelId", 7);
//                    List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
//                    panelContentItems = panelListConverter.panelContentsToPanelContentItems(panelContents);
//                }
//                panel.setPanelContentItems(panelContentItems);
//            }
//            List<PanelDto> panelDtos = panelListConverter.panelListToPanelDtoList(panels);
//            Set<PanelDto> panelDtos1 = new HashSet<>(panelDtos);
//            response.setPanelContentItemDtos(panelDtos1);
//            response.setCode(ShoppingRetCode.SUCCESS.getCode());
//            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
//            log.info("IShoppingHomepageServiceImpl.homepage effect row :" + panels.size());
//        } catch (Exception e) {
//            ExceptionProcessorUtils.wrapperHandlerException(response,e);
//            log.error("IShoppingHomepageServiceImpl.homepage occur Exception :" + e);
//        }
//
//        return response;
//    }
}
